import request from "../request";
//获取用户列表
async function getUserlist(props: any) {
  const data = await request({
    url: "users",
    method: "get",
    params: {
      ...props,
    },
  });
  return data;
}
//改变用户状态
async function changeUserState(uid: number, type: boolean) {
  const data = await request({
    url: `users/${uid}/state/${type}`,
    method: "put",
  });
  return data;
}
//添加用户
async function addUserList(props: Idata) {
  const data = await request({
    url: `users`,
    method: "post",
    data: props,
  });
  return data;
}
//编辑用户
async function EditUser(props: Idata) {
  const data = await request({
    url: `users/${props.id}`,
    method: "put",
    data: props,
  });
  return data;
}
// 删除用户
async function DeleteUser(id: number) {
  const data = await request({
    url: `users/${id}`,
    method: "delete",
    data: {
      id,
    },
  });
  return data;
}
// 分配角色
async function AddRole(props: Idata) {
  const data = await request({
    url: `users/${props.id}/role`,
    method: "put",
    data: props,
  });
  return data;
}
// users/:id/role

export default {
  getUserlist,
  changeUserState,
  addUserList,
  EditUser,
  DeleteUser,
  AddRole,
};
